package org.monster.boot;

/**
 * dos执行器<br>
 * 触发当前线程类实例是---->{@link DosContainerProxy}<br>
 * {@link DosContainerProxy}类的put方法执行唤醒{@link DosContainer}当前线程， 并使用
 * {@link SocketReceiverProxy}的receive方法接收。
 *
 * @author Monster
 */
public class DosExecutor extends Thread {

    /**
     * dos容器单例对象
     */
    private static final Container container = DosContainer.getInstance();
    /**
     * socket接收对象的代理类
     */
    private SocketReceiverProxy proxy;

    /**
     * 带参的构造方法({@link DosContainer} {@link SocketReceiverProxy})
     *
     * @param receiver 套接字接收器
     */
    public DosExecutor(SocketReceiver receiver) {
        this.proxy = new SocketReceiverProxy(receiver);
    }

    /**
     * 运行
     */
    @Override
    public void run() {
        while (true) {
            String dosCommand = container.get();
            if (dosCommand == null) {
                return;
            }
            proxy.receive(dosCommand);
        }
    }

}
